﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wcsServo.cache;
using wcsServo.dao;
using wcsServo.entity;
using wcsServo.utils;

namespace wcsServo.init
{
    public class InitLoading
    {
        public static void InitServo(string servoName)
        {
            string itemSql = "select * from PLC_ITEM";
            List<PlcItemEntity> items = DBFactory.QueryList<PlcItemEntity>(itemSql);
            string evaSql = $"select * from PLC_EVENT where belong_sys='{servoName}'";
            List<PlcEventEntity> events = DBFactory.QueryList<PlcEventEntity>(evaSql);
            GlobalCachePool.plcEvents_dict.Add(servoName, events);
            //1.对相关数据逐条进行核验
            if (items.Count > 0)
            {
                //缓存PLC_ITEM信息
                GlobalCachePool.plcItems_dict.Add(servoName, items);
            }

            //2.优先处理事件(PLC_EVENT与SCAN_EVENT)内容
            if (events.Count > 0)
            {
                foreach (PlcEventEntity eva in events)
                {
                    ServoUtils.InitPlcEvent(eva);
                }
            }
        }
    }
}
